﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Travel.API.Filters;
using Travel.Data;
using Travel.Data.Consts;
using Travel.Data.Dtos.TravelBusiness;
using Travel.Data.Inputs;
using Travel.Service.TravelBusiness;

namespace Travel.API.Controller
{
    /// <summary>
    /// 分类管理
    /// </summary>
    [ApiController]
    [Route("[controller]/[action]")]
    public class CategoryController :BaseController
    {
        private readonly ICategoryService _categoryService;

        public CategoryController( ICategoryService categoryService)
        {
            _categoryService = categoryService;
        }
        /// <summary>
        /// 查询所有分类
        /// </summary>
        /// <remarks>不需要登录即可访问的接口</remarks>
        [HttpGet]
        [AllowAnonymous]
        public Results<List<CategoryDto>> GetList() { 
        
            return _categoryService.GetList();
        }
        /// <summary>
        /// 添加或者修改分类
        /// </summary>
        /// <remarks>只能管理员操作</remarks>
        [HttpPost]
        [TravelAuthorize(AuthorizeRoleName.Administrator)]
        public Results<string> AddOrUpdate([FromBody] CategoryInput categoryInput) {
            return _categoryService.AddOrUpdate(categoryInput);
        }

        /// <summary>
        /// 删除一条分类
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        [TravelAuthorize(AuthorizeRoleName.Administrator)]
       public Task<Results<string>> Delete([FromBody]List<long> idList) {

            return _categoryService.Delete(idList.ToArray());
        }
    }
}
